local nanzhong = fk.CreateSkill{
    name = "lingling__nanzhong",
    dynamic_desc = function (self, player, lang)
        local str = "当你与其距离为1以内的角色成为【杀】的目标后，你可以令其"

        if player:getMark("@@lingling__beilie-success") == 0 then
            str = str .. "<font color='#009cff'>摸两张牌</font>"
            if player:getMark("@@lingling__beilie-fail") == 0 then
                str = str .. "/"
            end
        end
        if player:getMark("@@lingling__beilie-fail") == 0 then
            str = str .. "<font color='red'>弃置两张牌</font>"
        end

        str = str .. "，然后若此【杀】对其"

        if player:getMark("@@lingling__beilie-success") == 0 then
            str = str .. "<font color='#009cff'>未造成伤害</font>"
            if player:getMark("@@lingling__beilie-fail") == 0 then
                str = str .. "/"
            end
        end
        if player:getMark("@@lingling__beilie-fail") == 0 then
            str = str .. "<font color='red'>造成伤害</font>"
        end

        return str .. "，你失去1点体力。"
    end,
}
Fk:loadTranslationTable{
    ["lingling__nanzhong"] = "难终",
    [":lingling__nanzhong"] = "当你与其距离为1以内的角色成为【杀】的目标后，你可以令其<font color='#009cff'>摸两张牌</font>/<font color='red'>弃置两张牌</font>，然后若此【杀】对其<font color='#009cff'>未造成伤害</font>/<font color='red'>造成伤害</font>，你失去1点体力。",
    ["#lingling__nanzhong"] = "难终：你可以令 %dest 执行一项",
}

nanzhong:addEffect(fk.TargetConfirmed, {
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(nanzhong.name) and
        data.card.trueName == "slash" and player:distanceTo(target) <= 1
    end,
    on_cost = function (self, event, target, player, data)
        local choices = {}
        if player:getMark("@@lingling__beilie-success") == 0 then
            table.insert(choices, "draw2")
        end
        if player:getMark("@@lingling__beilie-fail") == 0 and not target:isNude() then
            table.insert(choices, "discard2")
        end
        if #choices > 0 then
            table.insert(choices, "Cancel")
            local choice = player.room:askToChoice(player, {
                choices = choices,
                all_choices = {"draw2","discard2","Cancel"},
                cancelable = true,
                prompt = "#lingling__nanzhong::"..target.id,
                skill_name = nanzhong.name,
            })
            if choice ~= "Cancel" then
                event:setCostData(self,choice)
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        data.extra_data = data.extra_data or {}
        if event:getCostData(self) == "draw2" then
            data.extra_data.lingling__nanzhong_draw = data.extra_data.lingling__nanzhong_draw or {}
            data.extra_data.lingling__nanzhong_draw[tostring(player.id)] = data.extra_data.lingling__nanzhong_draw[tostring(player.id)] or {}
            table.insert(data.extra_data.lingling__nanzhong_draw[tostring(player.id)], target.id)
            target:drawCards(2, nanzhong.name)
        else
            data.extra_data.lingling__nanzhong_discard = data.extra_data.lingling__nanzhong_discard or {}
            data.extra_data.lingling__nanzhong_discard[tostring(player.id)] = data.extra_data.lingling__nanzhong_discard[tostring(player.id)] or {}
            table.insert(data.extra_data.lingling__nanzhong_discard[tostring(player.id)], target.id)
            room:askToDiscard(target, {
                max_num = 2,
                min_num = 2,
                cancelable = false,
                include_equip = true,
                skill_name = nanzhong.name,
            })
        end
    end,
})

nanzhong:addEffect(fk.CardUseFinished, {
    is_delay_effect = true,
    anim_type = "negative",
    can_trigger = function (self, event, target, player, data)
        if data.card.trueName == "slash" and data.extra_data then
            local room = player.room
            if data.extra_data.lingling__nanzhong_draw and data.extra_data.lingling__nanzhong_draw[tostring(player.id)] then
                for _, id in ipairs(data.extra_data.lingling__nanzhong_draw[tostring(player.id)]) do
                    if data.damageDealt and data.damageDealt[room:getPlayerById(id)] then
                        return false
                    else
                        return true
                    end
                end
            end
            if data.extra_data.lingling__nanzhong_discard and data.extra_data.lingling__nanzhong_discard[tostring(player.id)] then
                for _, id in ipairs(data.extra_data.lingling__nanzhong_discard[tostring(player.id)]) do
                    if data.damageDealt and data.damageDealt[room:getPlayerById(id)] then
                        return true
                    end
                end
            end
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local num = 0
        if data.extra_data.lingling__nanzhong_draw and data.extra_data.lingling__nanzhong_draw[tostring(player.id)] then
            for _, id in ipairs(data.extra_data.lingling__nanzhong_draw[tostring(player.id)]) do
                if not data.damageDealt or not data.damageDealt[room:getPlayerById(id)] then
                    num = num + 1
                end
            end
        end
        if data.extra_data.lingling__nanzhong_discard and data.extra_data.lingling__nanzhong_discard[tostring(player.id)] then
            for _, id in ipairs(data.extra_data.lingling__nanzhong_discard[tostring(player.id)]) do
                if data.damageDealt and data.damageDealt[room:getPlayerById(id)] then
                    num = num + 1
                end
            end
        end
        player.room:loseHp(player, num, nanzhong.name)
    end,
})

return nanzhong